/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.opmviewer.graphviz;

import java.awt.Graphics2D;
import java.awt.Shape;
import java.util.Map;
import prefuse.data.Edge;
import prefuse.render.EdgeRenderer;
import prefuse.util.ColorLib;
import prefuse.visual.VisualItem;

/**
 *
 * @author grzegorz
 */
public class GraphvizEdgeRenderer extends EdgeRenderer {

    Map<String, EdgeShape> edgeShapes;

    public GraphvizEdgeRenderer(Map<String, EdgeShape> edgeShapes) {
        this.edgeShapes = edgeShapes;
    }

    @Override
    public Shape getRawShape(VisualItem item) {
        Edge e = (Edge) item;
        String id = e.getSourceNode().getString("NODE_ID")
                + "->" + e.getTargetNode().getString("NODE_ID");
        return edgeShapes.get(id).line;
    }

    @Override
    public void render(Graphics2D g, VisualItem item) {
        super.render(g, item);
        Edge e = (Edge) item;
        String id = e.getSourceNode().getString("NODE_ID")
                + "->" + e.getTargetNode().getString("NODE_ID");
        g.setPaint(ColorLib.getColor(item.getFillColor()));
        g.fill(edgeShapes.get(id).arrow);

    }
}
